//index.js
//获取应用实例
const app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    cartCount:app.globalData.cartCount,
    formData: {
      phone:'',
      authCode:'',
    },
   

    ischecked:false,
    PageCur: '',
    Page: {
      index: '/pages/index/index',
      equity: '/pages/equity/equity',
      order: '/pages/order/order',
      my: '/pages/my/my',
    }
  },
  checkInfo: function() {
    this.setData({
      agreementName: "agreementModal"
    })
  },
  okAgreementModal: function() {
    this.setData({
      ischecked: true,
      agreementName: null
    })
  },
  quitAgreementModal: function() {
    this.setData({
      ischecked: false,
      agreementName: null
    })
  },
  openAgreement: function() {
    wx.navigateTo({
      url: '/pages/agreement/index'
    })
  },
  hideModal(e) {
    this.setData({
      modalName: null
    })
  },
  //登录
  formSubmit: function(e) {
    // 表单验证
    console.log(999,e.detail.value);
    if (!/^1\d{10}$/.test(e.detail.value.phone)) {
      wx.showToast({
        title: '请输入正确的手机号',
        icon: 'none'
      });
      return;
    }
    if (!e.detail.value.authCode) {
      wx.showToast({
        title: '请输入认证码',
        icon: 'none'
      });
      return;
    }
    if (!this.data.ischecked) {
      wx.showToast({
        title: '请阅读并同意协议',
        icon: 'none'
      });
      return;
    }
    //登录
    let _this=this;
    wx.request({
      url:app.globalData.onlineUrl+"api/admin/xcxlogin",
      header:{'content-type': 'application/json'},
      method:"POST",
      data:{
        phone:e.detail.value.phone,
        authCode:e.detail.value.authCode
      },
      dataType:"json",
      complete:function(res) {
        console.log(666,res.data);
        if(res.data.code==250){
          wx.showToast({
            title: res.data.msg,
            icon: 'none'
          });
        }else{
          console.log(99999,res.data.data.userId);
          wx.setStorageSync('logininfo',{ phone: e.detail.value.phone,authCode: e.detail.value.authCode ,userId:res.data.data.userId})
          _this.setData({
            modalName: null
          })
          wx.switchTab({
            url:'/pages/order/index',
          })
        }
          
      }
    })
  },
  //订单菜单
  switchTab(e){
    console.log(e.currentTarget.dataset.cur);
    wx.switchTab({
      url: this.data.Page[e.currentTarget.dataset.cur],
    })
  },
  //客服
  phonecall() {
    wx.makePhoneCall({
      phoneNumber: '400-668-2024',
    })
  },
  onShow() {
},
  onUnload() {
  },
})

